package com.yuerlive.rainbow.module.live;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.base.BaseActivity;
import com.yuerlive.rainbow.entity.RecommendLive;
import com.yuerlive.rainbow.entity.User;
import com.yuerlive.rainbow.module.live.presenter.LiveFinishContract;
import com.yuerlive.rainbow.module.live.presenter.LiveFinishPresenter;
import com.yuerlive.rainbow.module.live.presenter.LiveRoomContract;
import com.yuerlive.rainbow.module.live.presenter.LiveRoomPresenter;
import com.yuerlive.rainbow.module.main.MainActivity;
import com.yuerlive.rainbow.utils.GlideUtil;
import com.yuerlive.rainbow.utils.LeakUtil;
import com.yuerlive.rainbow.utils.UserProxy;
import com.yuerlive.rainbow.widget.CircleImageView;
import com.yuerlive.rainbow.widget.timeselector.TextUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Admin on 2017/5/24.
 */

public class LiveFinishActivity extends BaseActivity implements LiveFinishContract.View {
    @BindView(R.id.civHeader)
    CircleImageView civHeader;
    @BindView(R.id.ivRecommendLive)
    ImageView ivRecommendLive;
    @BindView(R.id.ivLiveIcon)
    ImageView ivLiveIcon;
    @BindView(R.id.ivRecommendLive2)
    ImageView ivRecommendLive2;
    @BindView(R.id.ivLiveIcon2)
    ImageView ivLiveIcon2;
    @BindView(R.id.tvCompeleted)
    TextView tvCompeleted;
    List<RecommendLive> recommendLive;
    @BindView(R.id.imgConver)
    ImageView imgConver;
    LiveFinishContract.Presenter presenter;
    @BindView(R.id.rlRecommend1)
    RelativeLayout rlRecommend1;
    @BindView(R.id.rlRecommend2)
    RelativeLayout rlRecommend2;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_live_finish;
    }

    @Override
    protected void initViews() {
        //Todo 设置主播头像
        String conver = getIntent().getStringExtra("conver");
        String userIcon = getIntent().getStringExtra("icon");
        GlideUtil.loadBlur(this, conver, imgConver);

        GlideUtil.load(this, userIcon, civHeader);
        presenter = new LiveFinishPresenter(this);
        presenter.getRecommendLive();
        //需要一个liveIcon
        // setRecommendData(recommendLive);
    }

    private void setRecommendData(List<RecommendLive> recommendLive) {
        if (recommendLive != null && recommendLive.size() > 0) {
            GlideUtil.load(this, recommendLive.get(0).getLiveIcon(), ivRecommendLive);
            if (recommendLive.size() > 1) {
                GlideUtil.load(this, recommendLive.get(1).getLiveIcon(), ivRecommendLive2);
                rlRecommend2.setVisibility(View.VISIBLE);
            }else {
                rlRecommend2.setVisibility(View.GONE);
            }
        } else {
            rlRecommend1.setVisibility(View.GONE);
            rlRecommend2.setVisibility(View.GONE);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        LeakUtil.fixInputMethodManagerLeak(this);
    }

    @OnClick({R.id.tvCompeleted, R.id.rlRecommend1, R.id.rlRecommend2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvCompeleted:
                jumpToActivity(MainActivity.class);
                finish();
                break;
            case R.id.rlRecommend1:
                if (recommendLive != null && recommendLive.size() > 0) {
                    Intent i = new Intent();
                    i.setClass(mActivity, LiveRoomActivity.class);
                    i.putExtra("liveId", recommendLive.get(0).getLiveId());
                    i.putExtra("chatroomId", recommendLive.get(0).getChatRoomId());
                    i.putExtra("liveCover", recommendLive.get(0).getLiveIcon());
                    jumpToActivity(i);
                }
                finish();
                break;
            case R.id.rlRecommend2:
                if (recommendLive != null && recommendLive.size() > 1) {
                    Intent i2 = new Intent();
                    i2.setClass(mActivity, LiveRoomActivity.class);
                    i2.putExtra("liveId", recommendLive.get(1).getLiveId());
                    i2.putExtra("chatroomId", recommendLive.get(1).getChatRoomId());
                    i2.putExtra("liveCover", recommendLive.get(1).getLiveIcon());
                    jumpToActivity(i2);
                }
                finish();
                break;
        }
    }

    @Override
    public void setPresenter(LiveFinishContract.Presenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showRecommendLive(List<RecommendLive> recommendDatas) {
        this.recommendLive = recommendDatas;
        setRecommendData(recommendDatas);
    }
}
